package com.itkjb.leisurely.resource.sys.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itkjb.leisurely.core.model.SearchModel;
import com.itkjb.leisurely.resource.sys.model.SysStationModel;
import com.itkjb.leisurely.resource.sys.mapper.SysStationMapper;
import com.itkjb.leisurely.resource.sys.service.ISysDepartmentService;
import com.itkjb.leisurely.resource.sys.service.ISysStationService;
import com.itkjb.leisurely.core.base.service.impl.BaseServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * <p>
 * 岗位 服务实现类
 * </p>
 *
 * @author itkjb.com
 * @since 2020-08-11
 */
@Service
public class SysStationServiceImpl extends BaseServiceImpl<SysStationMapper, SysStationModel> implements ISysStationService {
    @Autowired
    ISysDepartmentService departmentService;

    @Override
    public List<SysStationModel> list(SearchModel<SysStationModel> searchModel) {
        return super.list(searchModel);
    }

    /**
     * wrapper 组装器，构造条件查询
     * @author itkjb.com
     * @date  2020-08-11
     * @param wrapper
     * @param model 条件
     **/
    @Override
    protected void assembleWrapper(QueryWrapper<SysStationModel> wrapper, SysStationModel model) {
        // （代码生成器生成）自动生成了，list查询的时候，条件组装，开发者自行删除不需要的条件
        // 岗位名称
        wrapper.lambda().like(StringUtils.isNotBlank(model.getName()), SysStationModel::getName, model.getName() );
        // 岗位编码
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getCode()), SysStationModel::getCode, model.getCode() );
        // 限定组织的顶级id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getTopid()), SysStationModel::getTopid, model.getTopid() );
        // 组织id
        if(StringUtils.isNotBlank(model.getDepId())){
            wrapper.lambda().in(SysStationModel::getDepId,this.departmentService.getIdAndSubIds(model.getDepId()) );
        }

        // 排序
        wrapper.lambda().eq(model.getPaixu() != null, SysStationModel::getPaixu, model.getPaixu() );
    }

    /**
     * wrapper 组装器，组装list查询时，查询的列
     * @author itkjb.com
     * @date  2020-08-11
     * @param wrapper
     * @param model
     * @return void
     * @since 2020-08-11
     **/
    @Override
    protected void buildListSelectColumns(QueryWrapper<SysStationModel> wrapper, SysStationModel model){
        buildCommonSelectColumns(wrapper, model);
    }

    /**
     * 组装列表查询的列（字段）
     * @date  2020-08-11
     * @param wrapper
     * @param model
     */
    protected void buildCommonSelectColumns(QueryWrapper<SysStationModel> wrapper, SysStationModel model){
        // 代码生成器生成，为了简化开发时，查询list时，查询指定字段，没必要查询所有参数
        wrapper.lambda().select(
            // id
            SysStationModel::getId,
            // 岗位名称
            SysStationModel::getName,
            // 岗位编码
            SysStationModel::getCode,
            // 限定组织的顶级id
            SysStationModel::getTopid,
            // 组织id
            SysStationModel::getDepId,
            // 排序
            SysStationModel::getPaixu,
            SysStationModel::getCreateTime
        );
    }


}
